<?php
/**
 * Created by PhpStorm.
 * User: yyq
 * Date: 2018/8/22
 * Time: 17:03
 * 属性分类model
 */

namespace Common\Model;


class AttributeModel extends CommonModel
{
    /**
     * @param int $attr_id
     * @return string
     */
    public function getAttrOption($attr_id = 0) {
        $result = $this->where(['if_show' => 'yes'])->select();

        $options = '';
        foreach ($result as $k => $v) {
            if($attr_id == $v['attr_id']) {
                $options .= '<option value="'.$v['attr_id'].'" selected>'.$v['attr_name'].'</option>';
            } else {
                $options .= '<option value="'.$v['attr_id'].'">'.$v['attr_name'].'</option>';

            }
        }
        return $options;
    }

    /**
     * @param $select
     * @return string
     */
    public function getAttrCheck($select = []) {
        $result = $this->where(['if_show' => 'yes'])->select();
        $check = "";
        foreach ($result as $k => $v) {
            if(in_array($v['attr_id'], $select)) {
                $check .= "<label style='float:left;margin-right:20px;' for=".$v."><input checked style='float:left;' class='level'  type='checkbox' id='".$v."' name='post[attr][]' value='".$v['attr_id']."' />".$v['attr_name']."</label>";
            } else {
                $check .= "<label style='float:left;margin-right:20px;' for=".$v['attr_id']."><input style='float:left;' class='level'  type='checkbox' id='".$v."' name='post[attr][]' value='".$v['attr_id']."' />".$v['attr_name']."</label>";
            }
        }
        return $check;
    }
}